﻿using System.Threading.Tasks;
using Thinker.SignChannel.Entities;
using Volo.Abp.DependencyInjection;
using Volo.Abp.Settings;

namespace Thinker.SignChannel.Results;

public class AllResultHandler(
    ISettingProvider settingProvider,
    PersonTimeCreator personTimeCreator,
    ResultBuilder resultBuilder) :
    ResultHandler(settingProvider), ITransientDependency
{
    protected override async Task CreateAsync(Record record, int calcResult)
    {
        if (calcResult == (int)SignResultCreateStyle.CreateAllOfTimeWhenSign)
        {
            var timeId = record.TimeId!.Value;
            await personTimeCreator.BuildAllIfNotAsync(timeId);

            var personId = record.PersonId!.Value;
            var personTime = await personTimeCreator.GetOrCreateAsync(personId, timeId);
            await resultBuilder.BuildAsync(personTime);
        }
    }
}